package com.taxi.driver.module.main.mine.wallet.withdrawalrecord.withdrawldetails;

import android.util.Log;

import com.qianxx.utils.RxUtil;
import com.taxi.driver.R;
import com.taxi.driver.common.BasePresenter;
import com.taxi.driver.data.user.UserRepository;
import com.taxi.driver.module.vo.WithdrawDetailVO;

import javax.inject.Inject;

public class WithdrawDetailsPresenter extends BasePresenter implements WithdrawDetailsContract.Presenter {
    UserRepository mUserRepository;
    WithdrawDetailsContract.View mView;

    @Inject
    public WithdrawDetailsPresenter(UserRepository userRepository,WithdrawDetailsContract.View view) {
        mUserRepository = userRepository;
        mView = view;
    }

    @Override
    public void reqWithdrawalDetails(String cashUuid) {
        mUserRepository.getWithdrawalInfo(cashUuid)
                .map(WithdrawDetailVO::createFrom)
                .compose(RxUtil.applySchedulers())
                .doOnSubscribe(() -> mView.showLoadingView(false))
                .doAfterTerminate(() -> mView.hideLoadingView())
                .subscribe(vo -> {
                    mView.showWithdrawalDetails(vo);
                }, ex -> {
                    Log.i("cashUuid--",cashUuid+"");
                    Log.i("cashUuid--",ex.getLocalizedMessage()+"");
                    showNetworkError(ex, R.string.network_error, mView, mUserRepository);
                });
    }
}
